/*==================================================
Project:       Targeting Social Programs
Authors:       Diether W. Beuermann
               Bridget Hoffmann        
               Marco Stampini 
               David L. Vargas
               Diego Vera-Cossio
----------------------------------------------------
Creation Date:    May 2023
Modification Date:   
Do-file version:    01
References:          
Output:             
==================================================*/


/*==================================================
            0: Program set up
==================================================*/
*Written on STATA 17
drop _all
set varabbrev off	// no variable abbreviations allowed (personal preference)

** source dir
cd "${dir5r}" // graph dir

/*==================================================
        1: load and plot
==================================================*/

// Load data from F4 models
use "${dir3r}/03_auxiliar/Boostrap_estimates.dta" , clear


****** Moral hazard

    #delimit ;
tw (connected exclusion_err year if type_m ==  "Baseline", 
        mcolor(red%80) lcolor(red%80) msym(S) ) 
    (rcap exclusion_err_uci exclusion_err_lci year if type_m ==  "Baseline", 
        lcolor(red%80)  )	
    (connected exclusion_err year if model_n ==  6  & type_m ==  "OLS", 
        mcolor(black%80) lcolor(black%80) msym(0) lpattern(-))
        (rcap exclusion_err_uci exclusion_err_lci year if model_n ==  6  & type_m ==  "OLS", 
        lcolor(black%80)  lpattern(-))
    (connected exclusion_err year if model_n ==10 & type_m ==  "OLS", 
        mcolor(navy%80) lcolor(navy%80) msym(T) ) 
        (rcap exclusion_err_uci exclusion_err_lci year if model_n ==10 & type_m ==  "OLS", 
        lcolor(navy%80) ) ,
    legend(order(1 "Benchmark PMT"		 			
                3 "Dynamic " 					
                5 "Dynamic - Moral hazard" 
                ) pos(6) row(2))
                
    ytitle("Exclusion Error")
    xtitle("Year")
    xlabel(2019(1)2021)
    ylabel(30(5)50)
    name(A, replace)
;
#delimit cr
graph export "FA5_a_moralhazard.png", as(png) replace width(1200)
graph export "FA5_a_moralhazard.pdf", as(pdf) replace 

    #delimit ;
    tw (connected inclusion_err year if type_m ==  "Baseline", 
        mcolor(red%80) lcolor(red%80) msym(S) ) 
    (rcap inclusion_err_uci inclusion_err_lci year if type_m ==  "Baseline", 
        lcolor(red%80)  )	
    (connected inclusion_err year if model_n ==  6  & type_m ==  "OLS", 
        mcolor(black%80) lcolor(black%80) msym(0) lpattern(-))
        (rcap inclusion_err_uci inclusion_err_lci year if model_n ==  6  & type_m ==  "OLS", 
        lcolor(black%80)  lpattern(-))
    (connected inclusion_err year if model_n ==10 & type_m ==  "OLS", 
        mcolor(navy%80) lcolor(navy%80) msym(T) ) 
        (rcap inclusion_err_uci inclusion_err_lci year if model_n ==10 & type_m ==  "OLS", 
        lcolor(navy%80) ) ,
        legend(order(1 "Benchmark PMT"		 			
                3 "Dynamic " 					
                5 "Dynamic - Moral hazard" 
                ) pos(6) row(2))
    ytitle("Inclusion Error")
    xtitle("Year")
    xlabel(2019(1)2021)
    ylabel(15(5)35)
    name(B, replace)
;
#delimit cr
graph export "FA5_b_moralhazard.png", as(png) replace width(1200)
graph export "FA5_b_moralhazard.pdf", as(pdf) replace 


    #delimit ;
    tw (connected crra year if type_m ==  "Baseline", 
        mcolor(red%80) lcolor(red%80) msym(S) ) 
    (rcap crra_uci crra_lci year if type_m ==  "Baseline", 
        lcolor(red%80)  )	
    (connected crra year if model_n ==  6  & type_m ==  "OLS", 
        mcolor(black%80) lcolor(black%80) msym(0) lpattern(-))
        (rcap crra_uci crra_lci year if model_n ==  6  & type_m ==  "OLS", 
        lcolor(black%80)  lpattern(-))
    (connected crra year if model_n ==10 & type_m ==  "OLS", 
        mcolor(navy%80) lcolor(navy%80) msym(T) ) 
        (rcap crra_uci crra_lci year if model_n ==10 & type_m ==  "OLS", 
        lcolor(navy%80) ) ,
    legend(order(1 "Benchmark PMT"		 			
                3 "Dynamic " 					
                5 "Dynamic - Moral hazard" 
                ) pos(6) row(2))
ytitle("Social Welfare (CRRA: {&rho} = 3)")
    xtitle("Year")
    xlabel(2019(1)2021)
    name(C, replace)
;
#delimit cr
graph export "FA5_c_moralhazard.png", as(png) replace width(1200)
graph export "FA5_c_moralhazard.pdf", as(pdf) replace 

    #delimit ;
    tw (connected hh_benefits year if type_m ==  "Baseline", 
        mcolor(red%80) lcolor(red%80) msym(S) ) 
    (rcap hh_benefits_uci hh_benefits_lci year if type_m ==  "Baseline", 
        lcolor(red%80)  )	
    (connected hh_benefits year if model_n ==  6  & type_m ==  "OLS", 
        mcolor(black%80) lcolor(black%80) msym(0) lpattern(-))
        (rcap hh_benefits_uci hh_benefits_lci year if model_n ==  6  & type_m ==  "OLS", 
        lcolor(black%80)  lpattern(-))
    (connected hh_benefits year if model_n ==10 & type_m ==  "OLS", 
        mcolor(navy%80) lcolor(navy%80) msym(T) ) 
        (rcap hh_benefits_uci hh_benefits_lci year if model_n ==10 & type_m ==  "OLS", 
        lcolor(navy%80) ) ,
    legend(order(1 "Benchmark PMT"		 			
                3 "Dynamic " 					
                5 "Dynamic - Moral hazard" 
                ) pos(6) row(2))

    ytitle("Per-household Transfer ($ USD PPP)")
    xtitle("Year")
    xlabel(2019(1)2021)
    name(D, replace)
;
#delimit cr
graph export "FA5_d_moralhazard.png", as(png) replace width(1200)
graph export "FA5_d_moralhazard.pdf", as(pdf) replace 